 $('.select2').select2()
	  $('#reservation').daterangepicker({
	  	locale:{format:'YYYY-MM-DD'}
	  });
	  $('#reservation').val('请选择时间');
	 
	 $(document).ready(function(){
	 	     var checkKind = 1;
	 	     $('.check1').click(function(){
	 	     	checkKind = 1;
	 	     	getData1(1);
	 	     })
	 	     $('.check2').click(function(){
	 	     	checkKind = 2;
	 	     	getData2(1);
	 	     })
	 	    function getData1(curr){
	 	          var data_rang = $('#reservation').val();//时间范围
				  
				  var start = data_rang.split(' -')[0];
				  var end = data_rang.split('- ')[1];
				  var timeOnoff = "False";
				  if(data_rang!=''&&data_rang!='请选择时间'){
				  	timeOnoff = "True"
				  }
				  $.ajax({
				  	type:"get",
				  	url:"https://www.retux.cn/MgProduct",
				  	async:true,
				  	data:{
				  		page:curr ,
				  		row: 10,
				  		end:end ,
				  		start:start ,
				  		Date:timeOnoff,
				  		Content:$('.sear_text').val()
				  	},
				  	success:function(data){
				  		if(data[0].length==0){
				  			layer.msg('暂无数据');
				  		}
				  		TableView(data[0]);
				  		pageDivd(curr,data[1]);
				  		
				  	}
				  });
			}
	 	    function getData2(curr){
	 	          var kind = $('.kind_sel').find('.select2-selection__rendered').text();
	 	          var label = $('.label_sel').find('.select2-selection__rendered').text();
				  $.ajax({
				  	type:"get",
				  	url:"https://www.retux.cn/MgProduct2",
				  	async:true,
				  	data:{
				  		page:curr ,
				  		row: 10,
				  		kind: kind,
				  		label: label
				  	},
				  	success:function(data){
				  		if(data[0].length==0){
				  			layer.msg('暂无数据');
				  		}
				  		TableView(data[0]);
				  		pageDivd(curr,data[1]);
				  	}
				  });
			}
	 	    getData1(1);
	 	    function pageDivd(curr,page_num){
	 	    	layui.use(['laypage', 'layer'], function(){
				  var laypage = layui.laypage
				  ,layer = layui.layer;
				    laypage.render({
				    elem: 'demo7'
				    ,count: page_num
				    ,limit:10
				    ,curr:curr
				    ,jump: function(obj,first){
				    	if(!first){
				    		if(checkKind==1){
				    			getData1(obj.curr);
				    		}else{
				    			getData2(obj.curr);
				    		}
				    		
				    	}
				    }
				  });
				})
	 	    }
	 	    function TableView(data){
	 	    	console.log(1)
	 	    	$('.table_data').html('');
	 	    	for (var i=0;i<data.length;i++) {
	 	    		var radio1,radio2,radio3;
	 	    		if(data[i][6].indexOf('新品')>-1){
	 	    			radio1 = '<input type="radio" checked="checked" disabled="disabled">';
	 	    		}else{
	 	    			radio1 = '<input type="radio" disabled="disabled">';
	 	    		}
	 	    		if(data[i][6].indexOf('热卖')>-1){
	 	    			radio2 = '<input type="radio" checked="checked" disabled="disabled">';
	 	    		}else{
	 	    			radio2 = '<input type="radio" disabled="disabled">';
	 	    		}
	 	    		if(data[i][6].indexOf('推荐')>-1){
	 	    			radio3 = '<input type="radio" checked="checked" disabled="disabled">';
	 	    		}else{
	 	    			radio3 = '<input type="radio" disabled="disabled">';
	 	    		}
	 	    		
	 	    		var trText = `<tr>
		      		    		<td><input  index="${data[i][0]}" type="checkbox" /></input></td>
		      		    		<td>${data[i][0]}</td>
		      		    		<td>${data[i][1]}</td>
		      		    		<td>
		      		    			<img src="${data[i][2]}" height="50"/>
		      		    		</td>
		      		    		<td>
		      		    			${data[i][3]}
		      		    		</td>
		      		    		<td>
		      		    			￥${data[i][4]}
		      		    		</td>
		      		    		<td>
		      		    			${data[i][5]}
		      		    		</td>
		      		    		<td>
		      		    			<div>
		      		    				<label class="label1">新品</label>${radio1}
		      		    			</div>
		      		    			<div>
		      		    				<label class="label2">热卖</label>${radio2}
		      		    			</div>
		      		    			<div>
		      		    				<label class="label3">推荐</label>${radio3}
		      		    			</div>
		      		    			
		      		    		</td>
		      		    		<td index="${data[i][0]}">
		      		    			<div>
		      		    				<a class="detail" href="#">查看</a>
		      		    				<a class="go_down" href="#">下架</a>
		      		    			</div>
		      		    			<div>
		      		    				<a class='add_btn' href="#">新增</a>
		      		    				<a class="edit_btn" href="#">修改</a>
		      		    			</div>
		      		    		</td>
		      		    	</tr>`;
		      		    	
		      		 $('.table_data').append(trText) ;  	
		      		    	
	 	    	}
	 	    	
	 	    	lookDetail();
	 	    }
	 	    
	 	    $("#check_all").click(function(){
	 	    	if($(this).prop('checked')==true){
	 	    		
	 	    		$("tbody").find('input[type=checkbox]').prop('checked','checked')
	 	    	}else{
	 	    		$("tbody").find('input[type=checkbox]').prop('checked',false)
	 	    	}
	 	    })
	 	    
	 	    function lookDetail(){
	 	    	$('.detail').click(function(){
	 	    		var Index = $(this).parent().parent().attr('index');
	 	    		window.location.href="http://119.23.212.200:30000/product_details.html?Index="+Index;
	 	    	})
	 	    	$('.add_btn').click(function(){
	 	    		var Index = $(this).parent().parent().attr('index');
	 	    		window.location.href="http://119.23.212.200:30000/new_product2.html?Index="+Index;
	 	    	})
	 	    	$('.edit_btn').click(function(){
	 	    		var Index = $(this).parent().parent().attr('index');
	 	    		window.location.href="http://119.23.212.200:30000/new_product3.html?Index="+Index;
	 	    	})
	 	    	$('.go_down').click(function(){
	 	    		var Index = $(this).parent().parent().attr('index');
	 	    		var CheckIn = $("tbody").find('input[type=checkbox]:checked');
	 	    		console.log(CheckIn.length)
	 	    		var IndexArry = [];
	 	    		if(CheckIn.length>0){
		 	    		for (var i=0;i<CheckIn.length;i++) {
		 	    			IndexArry.push(CheckIn.eq(i).attr('index'));
		 	    		}
	 	    		}else{
	 	    			IndexArry.push(Index)
	 	    		}
	 	    		var self = $(this);
	 	    		$.ajax({
	 	    			type:"get",
	 	    			url:"https://www.retux.cn/MgProductRecycleSubmit",
	 	    			async:true,
	 	    			data:{
	 	    				Id:IndexArry.join('-')
	 	    			},
	 	    			success:function(data){
	 	    				if(data=='success'){
	 	    					layer.msg('成功下架',{time:500},function(){
	 	    						location.reload();
	 	    					})
	 	    				}else{
	 	    					layer.msg('操作失败')
	 	    				}
	 	    				
	 	    			}
	 	    			
	 	    		});
	 	    	})
	 	    	
	 	    }
				  
	 })